#ifndef QUERY_PARSER
#define QUERY_PARSER

#include "types.h"


/*
 * Function for parsing GET and POST query and puts values
 * into map<string, string>
 */
void parse(char *query, t_args *args) {
    char *_start, *_end, *_midle;

    _start = _end = _midle = query;
    for (; *_end; _end++)
        switch(*_end) {
        case '=':
            _midle = _end;
                break;

            case '&':
                if(_start != _end) {
                    *_midle = '\0'; *_end = '\0';
                    (*args)[_start] = _midle + 1;
                    *_midle = '='; *_end = '&';
                }
        _start = _midle = _end; _start++;
        break;
    }

    if (_start != _end) {
        *_midle = '\0';
        (*args)[_start] = _midle + 1;
        *_midle = '=';
    }
}

#endif // QUERY_PARSER_INL_H
